package com.bungarus.rm.model;

import com.fasterxml.jackson.annotation.JsonUnwrapped;
import org.springframework.stereotype.Component;

/**
 * Created by tang on 2019/1/13.
 */
@Component
public class IDMakerScope implements Containable{
    @JsonUnwrapped
    private UniqueNodeID id;

    private int worker;
    private int dc;

    public static Builder newBuilder() {
        return new Builder();
    }

    public static class Builder {
        private IDMakerScope scope = new IDMakerScope();
        private UniqueNodeID id = new UniqueNodeID();

        public Builder cluster(int clusterId) {
            id.setClusterId(clusterId);
            return this;
        }

        public Builder node(int nodeId) {
            id.setNodeId(nodeId);
            return this;
        }

        public Builder worker(int worker) {
            scope.setWorker(worker);
            return this;
        }

        public Builder dc(int dc) {
            scope.setDc(dc);
            return this;
        }

        public IDMakerScope build() {
            scope.setId(id);
            return scope;
        }
    }

    @Override
    public String toString() {
        return "IDMakerScope{" +
                "id=" + id +
                ", worker=" + worker +
                ", dc=" + dc +
                '}';
    }

    @Override
    public boolean equals(Object o) {
        if (this == o) return true;
        if (!(o instanceof IDMakerScope)) return false;

        IDMakerScope scope = (IDMakerScope) o;

        return !(getId() != null ? !getId().equals(scope.getId()) : scope.getId() != null);

    }

    @Override
    public int hashCode() {
        return getId() != null ? getId().hashCode() : 0;
    }

    public UniqueNodeID getId() {
        return id;
    }

    public void setId(UniqueNodeID id) {
        this.id = id;
    }

    public int getWorker() {
        return worker;
    }

    public void setWorker(int worker) {
        this.worker = worker;
    }

    public int getDc() {
        return dc;
    }

    public void setDc(int dc) {
        this.dc = dc;
    }
}
